import Vue from 'vue'
import Vuex from 'vuex'
import createpersistedState from 'vuex-persistedstate'


Vue.use(Vuex)



export default new Vuex.Store({

  plugins: [createpersistedState({
    reducer: (state) => {
        return {
            userimg: state.userimg,
            username: state.username,
            userid:state.userid,
            login:state.login,
            songnew:state.songnew,
            songlist:state.songlist,
            // musicurl:state.musicurl,
            // musicuser:state.musicuser
        }
    }
}

)],


  state: {
    musicurl:[],  //当前音乐播放地址
    songlist:[],  //当前正在播放音乐的歌单
    musicuser:{},  //当前音乐名字图片
    isplay:true,
    indexid:null,
    index:null,
    login:'',
    userid:'',
    userimg:'',
    username:'点击头像登录',
    songnew:[],  //当前播放歌单的数组
    indexoid:null,
    search:'',
    searchsongslist:[],
    searname:'',
    currtime:''


  },
  mutations: {
    currtime(state,time){
      state.currtime = time
    },
    searnames(state,name){
        state.searname = name
    },
    searchname(state,list){
        state.searchsongslist = list  
    },
    indexxgaiiod(state,index){
        state.indexoid = index
    },
    indexiodnull(state){
        state.indexoid = null
    },
    //点击播放全部修改歌单列表inedex=0
    // index(state){
    //   state.index = 0
    //   state.songlist[0].id = state.indexid
    // },
    // qingkong(state){
    //     state.songlist = []
    // },
    songnew(state){
      state.songnew = state.songlist
    },
    indexnull(state){
      state.indexoid = ''
    },
    indexdianji(state,index){
      state.index = index
    },
    indexjia(state){
      // if(state.index >)
      state.index++
      let indexdd = state.index
      

      state.indexid = state.songnew[indexdd].id
    },
    indexjian(state){
      if(state.index>0){
      state.index--
      let indexdd = state.index

      state.indexid = state.songnew[indexdd].id
      }
      
    },
    indexxgai(state,data){
        state.indexid = data
    },
    musicurlhandle(state,url){
        state.musicurl = url
        // state.isplay=true
    },
  
    musicuserhandle(state,value){
        state.musicuser = value
    },
    songlist(state,data){
        state.songlist = data
    },
    isplayhandle(state){
      state.isplay=!state.isplay
    },
    isplaybofang(state){
      state.isplay=false
    },
    islogin(state){
      state.login=200
    },
    songlists(state,data){
      state.songlist = data

    },
    tuichu(state){
      state.userid = '',
      state.userimg = '',
      state.username = '点击头像登录',
      state.login = ''
    }
  },
  actions: {
  },
  modules: {
  }
})
